package com.ljd.gulimall.product.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ljd.gulimall.product.entity.CategoryEntity;
import com.ljd.gulimall.product.service.CategoryService;
import com.ljd.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author 23817
 * @Date 11:10 2023/3/4
 * @Version 1.0
 */
@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/index.html"})
    public String getIndex(Model model) {
        List<CategoryEntity> categoryEntities = categoryService.list(new LambdaQueryWrapper<CategoryEntity>().eq(CategoryEntity::getParentCid, '0'));

        model.addAttribute("categories", categoryEntities);
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String,List<Catelog2Vo>> getCatlogJson() {
        return categoryService.getCatlogJson();
    }

    @ResponseBody
    @GetMapping("/hello")
    public String str() {
        return "hello";
    }

}
